//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
//

#ifndef ETHERNET_H_
#define ETHERNET_H_

#include <stdio.h>
#include <string.h>
#include <omnetpp.h>

#include "eth_pck_m.h"
#include "ip_pck_m.h"
#include "arp_m.h"
#include "ageing_m.h"

using namespace std;

class Ethernet : public cSimpleModule
{
    private:
        string myIPAddress;
        string myMacAddress;
        cChannel *txSwitchChannel;
        string arpTable[4][2];
        cQueue *txQueue;
        int agingTime;
        int IPv4_type;
        int ARP_type;
        int ARP_request;
        int ARP_reply;
        int IP_row;
        int MAC_row;
    protected:
        virtual void initialize();
        virtual void handleMessage(cMessage *msg);
        virtual void handleARPMessage(ARP *msg);
        virtual void deployARPRequest(IP_pck *msg);
        virtual void handleEthMessage(Eth_pck *msg);
        virtual void handleIPMessage(IP_pck *msg);
        virtual void handleAgeingMessage(Ageing *msg);
        virtual void forwardToSwitch(Eth_pck *msg);
        virtual void forwardToIpGate(cMessage *msg);
        virtual int  ipEntry(string address);
        virtual bool macExists(int index);
};

#endif /* ETHERNET_H_ */
